home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / mysql-test / install_test_db next >
Encoding:
Text File  |  2003-01-22  |  7.2 KB  |  218 lines  |  [TEXT/ttxt]

  1. #!/bin/sh
  2. # Copyright (C) 1997, 1998, 1999 TCX DataKonsult AB & Monty Program KB & Detron HB
  3. # For a more info consult the file COPYRIGHT distributed with this file
  4.  
  5. # This scripts creates the privilege tables db, host, user, tables_priv,
  6. # columns_priv in the mysql database, as well as the func table.
  7.  
  8. if [ x$1 = x"-bin" ]; then
  9.  shift 1
  10.  execdir=../bin
  11.  bindir=../bin
  12.  BINARY_DIST=1
  13.  fix_bin=mysql-test
  14. else
  15.  execdir=../sql
  16.  bindir=../client
  17.  fix_bin=.
  18. fi
  19.  
  20. vardir=var
  21. logdir=$vardir/log
  22. if [ x$1 = x"-slave" ] 
  23. then
  24.  shift 1
  25.  data=var/slave-data
  26.  ldata=$fix_bin/var/slave-data
  27. else
  28.  data=var/master-data
  29.  ldata=$fix_bin/var/master-data
  30. fi
  31.  
  32. mdata=$data/mysql
  33.  
  34.  
  35. if test ! -x $execdir/mysqld
  36. then
  37.   echo "mysqld is missing - looked in $execdir"
  38.   exit 1
  39. fi
  40.  
  41. # On IRIX hostname is in /usr/bsd so add this to the path
  42. PATH=$PATH:/usr/bsd
  43. hostname=`hostname`        # Install this too in the user table
  44. hostname="$hostname%"        # Fix if not fully qualified hostname
  45.  
  46.  
  47. #create the directories
  48. [ -d $vardir ] || mkdir $vardir
  49. [ -d $logdir ] || mkdir $logdir
  50.  
  51. # Create database directories mysql & test
  52. if [ -d $data ] ; then rm -rf $data ; fi
  53. mkdir $data $data/mysql $data/test 
  54.  
  55. #for error messages
  56. if [ x$BINARY_DIST = x1 ] ; then
  57. basedir=..
  58. else
  59. basedir=.
  60. rm -rf share
  61. mkdir  share
  62. ln -f -s ../../sql/share share/mysql 
  63. fi
  64.  
  65. # Initialize variables
  66. c_d="" i_d=""
  67. c_h="" i_h=""
  68. c_u="" i_u=""
  69. c_f="" i_f=""
  70. c_t="" c_c=""
  71.  
  72. # Check for old tables
  73. if test ! -f $mdata/db.frm
  74. then
  75.   # mysqld --bootstrap wants one command/line
  76.   c_d="$c_d CREATE TABLE db ("
  77.   c_d="$c_d   Host char(60) DEFAULT '' NOT NULL,"
  78.   c_d="$c_d   Db char(64) DEFAULT '' NOT NULL,"
  79.   c_d="$c_d   User char(16) DEFAULT '' NOT NULL,"
  80.   c_d="$c_d   Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  81.   c_d="$c_d   Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  82.   c_d="$c_d   Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  83.   c_d="$c_d   Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  84.   c_d="$c_d   Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  85.   c_d="$c_d   Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  86.   c_d="$c_d   Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  87.   c_d="$c_d   References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  88.   c_d="$c_d   Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  89.   c_d="$c_d   Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  90.   c_d="$c_d PRIMARY KEY Host (Host,Db,User),"
  91.   c_d="$c_d KEY User (User)"
  92.   c_d="$c_d )"
  93.   c_d="$c_d comment='Database privileges';"
  94.   
  95.   i_d="INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');
  96.   INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');"
  97. fi
  98.  
  99. if test ! -f $mdata/host.frm
  100. then
  101.   c_h="$c_h CREATE TABLE host ("
  102.   c_h="$c_h  Host char(60) DEFAULT '' NOT NULL,"
  103.   c_h="$c_h  Db char(64) DEFAULT '' NOT NULL,"
  104.   c_h="$c_h  Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  105.   c_h="$c_h  Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  106.   c_h="$c_h  Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  107.   c_h="$c_h  Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  108.   c_h="$c_h  Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  109.   c_h="$c_h  Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  110.   c_h="$c_h  Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  111.   c_h="$c_h  References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  112.   c_h="$c_h  Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  113.   c_h="$c_h  Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  114.   c_h="$c_h  PRIMARY KEY Host (Host,Db)"
  115.   c_h="$c_h )"
  116.   c_h="$c_h comment='Host privileges;  Merged with database privileges';"
  117. fi
  118.  
  119. if test ! -f $mdata/user.frm
  120. then
  121.   c_u="$c_u CREATE TABLE user ("
  122.   c_u="$c_u   Host char(60) DEFAULT '' NOT NULL,"
  123.   c_u="$c_u   User char(16) DEFAULT '' NOT NULL,"
  124.   c_u="$c_u   Password char(16) DEFAULT '' NOT NULL,"
  125.   c_u="$c_u   Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  126.   c_u="$c_u   Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  127.   c_u="$c_u   Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  128.   c_u="$c_u   Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  129.   c_u="$c_u   Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  130.   c_u="$c_u   Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  131.   c_u="$c_u   Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  132.   c_u="$c_u   Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  133.   c_u="$c_u   Process_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  134.   c_u="$c_u   File_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  135.   c_u="$c_u   Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  136.   c_u="$c_u   References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  137.   c_u="$c_u   Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  138.   c_u="$c_u   Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  139.   c_u="$c_u   PRIMARY KEY Host (Host,User)"
  140.   c_u="$c_u )"
  141.   c_u="$c_u comment='Users and global privileges';"
  142.  
  143.   i_u="INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  144.   INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  145.   REPLACE INTO user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  146.   
  147.   INSERT INTO user VALUES ('localhost','','','N','N','N','N','N','N','N','N','N','N','N','N','N','N');
  148.   INSERT INTO user VALUES ('$hostname','','','N','N','N','N','N','N','N','N','N','N','N','N','N','N');"
  149. fi
  150.  
  151. if test ! -f $mdata/func.frm
  152. then
  153.   c_f="$c_f CREATE TABLE func ("
  154.   c_f="$c_f   name char(64) DEFAULT '' NOT NULL,"
  155.   c_f="$c_f   ret tinyint(1) DEFAULT '0' NOT NULL,"
  156.   c_f="$c_f   dl char(128) DEFAULT '' NOT NULL,"
  157.   c_f="$c_f   type enum ('function','aggregate') NOT NULL,"
  158.   c_f="$c_f   PRIMARY KEY (name)"
  159.   c_f="$c_f )"
  160.   c_f="$c_f   comment='User defined functions';"
  161. fi
  162.  
  163. if test ! -f $mdata/tables_priv.frm
  164. then
  165.   c_t="$c_t CREATE TABLE tables_priv ("
  166.   c_t="$c_t   Host char(60) DEFAULT '' NOT NULL,"
  167.   c_t="$c_t   Db char(64) DEFAULT '' NOT NULL,"
  168.   c_t="$c_t   User char(16) DEFAULT '' NOT NULL,"
  169.   c_t="$c_t   Table_name char(60) DEFAULT '' NOT NULL,"
  170.   c_t="$c_t   Grantor char(77) DEFAULT '' NOT NULL,"
  171.   c_t="$c_t   Timestamp timestamp(14),"
  172.   c_t="$c_t   Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL,"
  173.   c_t="$c_t   Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,"
  174.   c_t="$c_t   PRIMARY KEY (Host,Db,User,Table_name),"
  175.   c_t="$c_t   KEY Grantor (Grantor)"
  176.   c_t="$c_t )"
  177.   c_t="$c_t   comment='Table privileges';"
  178. fi
  179.  
  180. if test ! -f $mdata/columns_priv.frm
  181. then
  182.   c_c="$c_c CREATE TABLE columns_priv ("
  183.   c_c="$c_c   Host char(60) DEFAULT '' NOT NULL,"
  184.   c_c="$c_c   Db char(64) DEFAULT '' NOT NULL,"
  185.   c_c="$c_c   User char(16) DEFAULT '' NOT NULL,"
  186.   c_c="$c_c   Table_name char(64) DEFAULT '' NOT NULL,"
  187.   c_c="$c_c   Column_name char(64) DEFAULT '' NOT NULL,"
  188.   c_c="$c_c   Timestamp timestamp(14),"
  189.   c_c="$c_c   Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,"
  190.   c_c="$c_c   PRIMARY KEY (Host,Db,User,Table_name,Column_name)"
  191.   c_c="$c_c )"
  192.   c_c="$c_c   comment='Column privileges';"
  193. fi
  194.  
  195. if $execdir/mysqld --no-defaults --bootstrap --skip-grant-tables \
  196.     --basedir=$basedir --datadir=$ldata --skip-innodb --skip-bdb --skip-gemini << END_OF_DATA
  197. use mysql;
  198. $c_d
  199. $i_d
  200.  
  201. $c_h
  202. $i_h
  203.  
  204. $c_u
  205. $i_u
  206.  
  207. $c_f
  208. $i_f
  209.  
  210. $c_t
  211. $c_c
  212. END_OF_DATA
  213. then
  214.     exit 0
  215. else
  216.     exit 1
  217. fi
  218.